const mongoose = require('mongoose')

const articleSchema = mongoose.Schema({
  title:{
    type: String,
    required: true,
    default:'标题'
  },
  date:{
    type: Date,
    default: Date.now
  },
  content:{
    type:String,
    required:true,
    default:'咋没东西'
  },
  topic:{
    type: Array,
    required: true,
    default: '杂谈'
  },
  desc:{
    type: String,
    required: true,
    default:'点进来看看说了啥...'
  }

})

const Article = mongoose.model('Article', articleSchema)

const getArticles = function(callback, limit) {
  Article.find(callback).limit(limit)
}

const addArticle = (article, callback) => {
  Article.create(article, callback)
}

const getArticleById = (id, callback) => {
  Article.findById(id, callback)
}
module.exports = {
  Article,
  getArticles,
  getArticleById,
  addArticle  
}